#ifndef _WII_MMGR_H_
#define _WII_MMGR_H_

#include "../sleipner_config.h"
#ifdef _PLATFORM_WII

//////////////////////////////////////////////////////
// The wii doesn't provide basic new/delete or malloc functionality
// to ensure that we can do simple cross-buildings, we'll do some
// quick functions here to emulate that functionality


/// complex interface for things like frame-buffers and custom heaps
#ifdef __cplusplus
extern "C" {
#endif

// C-style defines, as this file's included in C legacy code
#define	HEAP_MEM1				0
#define	HEAP_MEM2				1
#define	HEAP_UNIT_16			2
#define	HEAP_UNIT_32			3
#define	HEAP_UNIT_64			4
#define	HEAP_UNIT_256			5
#define	HEAP_C					6
#define HEAP_UNKNOWN			7
#define MMGR_HEAPS				unsigned int

void			WiiMMGR_Init();
void			WiiMMGR_Shutdown();

void*			WiiMMGR_Alloc(MMGR_HEAPS HeapID, unsigned int Size, int Alignment);
void*			WiiMMGR_Realloc(void* pArea, unsigned int	OldSize, unsigned int NewSize, int Alignment);
void			WiiMMGR_Free(void* pData);
unsigned int	WiiMMGR_SetOwner(const	char* file, unsigned int line, const	char* func);


// get access to the 4MB scratchpad memory
void*		WiiMMGR_ScratchPad();

// C function interface for legacy code


#define DEFAULT_ALIGNMENT  4
#define	MMGR_Alloc(_ALLOC_SIZE) ((WiiMMGR_SetOwner(__FILE__,__LINE__,__FUNCTION__)) ? WiiMMGR_Alloc(HEAP_MEM2, _ALLOC_SIZE, DEFAULT_ALIGNMENT) : NULL)
#define	MMGR_AllocEx(_HEAPID, _ALLOC_SIZE, _ALIGNMENT) ((WiiMMGR_SetOwner(__FILE__,__LINE__,__FUNCTION__)) ? WiiMMGR_Alloc(_HEAPID, _ALLOC_SIZE, _ALIGNMENT): NULL)
#define	MMGR_Free(_DATA_POINTER) { WiiMMGR_SetOwner(__FILE__,__LINE__,__FUNCTION__); WiiMMGR_Free(_DATA_POINTER); }
#define MMGR_Realloc(_DATA_POINTER, _OLD_SIZE, _NEW_SIZE, _ALIGNMENT) (WiiMMGR_SetOwner(__FILE__,__LINE__,__FUNCTION__)) ? WiiMMGR_Realloc(_DATA_POINTER, _OLD_SIZE, _NEW_SIZE, _ALIGNMENT): NULL
#ifdef __cplusplus
}

// reporting functions
struct		WiiAllocation
{
	char*	File;
	char*	Func;
	unsigned int Line;
	unsigned int Size;
};

const char*	WiiMMGR_ToString();
int			WiiMMGR_MemUsage(unsigned int& Mem1, unsigned int& Mem2);
unsigned int WiiMMGR_AllAllocations(WiiAllocation*	AllocationA);

void* operator new[](std::size_t size) throw(const char*);
//void* operator new[](std::size_t size, const std::nothrow_t&)throw();
void*	operator new(size_t reportedSize);
void*	operator new[](size_t reportedSize);
void	operator delete(void *reportedAddress) throw();
void	operator delete[](void *reportedAddress) throw();


//////////////HACK HACK!
/*#include "nommgr.h"
#define	new		(WiiMMGR_SetOwner (__FILE__,__LINE__,__FUNCTION__) ? new : NULL
#define	delete	(WiiMMGR_SetOwner(__FILE__,__LINE__,__FUNCTION__) ? delete : NULL
#define	malloc(sz)	MMGR_Alloc(sz)
//#define	calloc(sz)	MMGR_Alloc(sz)
//#define	realloc(ptr,sz)	MMGR_Realloc(ptr, sz, sz, DEFAULT_ALIGNMENT)
#define	free(ptr)	MMGR_Free(ptr)
*/


#endif //__cplusplus



#endif //_PLATFORM_WII
#endif //_WII_MMGR_H_